<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
    var formDesignDataGrid;
    $(function() {
        formDesignDataGrid = $('#formDesignDataGrid').datagrid({
            url : '${path}/formDesign/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
                {
                    width : '400',
                    title : '标题',
                    field : 'title'
                },
                {
                    width : '100',
                    title : '表名',
                    field : 'tableName'
                },
                {
                width : '200',
                title : '类型',
                field : 'type'
            },
                {
                width : '100',
                title : '主键',
                field : 'id'
                ,hidden : true
            },
                {
                width : '100',
                title : '版本号',
                field : 'version'
            },

                {
                    width: '100',
                    title: '状态',
                    field: 'valid',
                    formatter : function (value, row, index) {
                        if(value==1){
                            return '有效'
                        }else{
                            return '无效'
                        }
                    }
            }
            ]],
            frozenColumns : [ [{
                field : 'action',
                title : '操作',
                width : 150,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="formDesign-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editFormDesignFun(\'{0}\');" >编辑</a>', row.id);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="formDesign-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteFormDesignFun(\'{0}\');" >删除</a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.formDesign-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.formDesign-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#formDesignToolbar'
        });
    });

    function addFormDesignFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 300,
            href : '${path}/formDesign/addPage',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = formDesignDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#formDesignAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function editFormDesignFun(id) {
        if (id == undefined) {
            var rows = formDesignDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            formDesignDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path}/formDesign/editPage/' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = formDesignDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#formDesignEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteFormDesignFun(id) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = formDesignDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            formDesignDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path}/formDesign/delete/'+id, {}
                , function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        formDesignDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
     function viewFormDesignFun(id) {
        if (id == undefined) {
            var rows =  formDesignDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
             formDesignDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '查看',
            width : 800,
            height : 450,
            href : '${path}/formDesign/viewPage/' + id,
        });
    }
    function searchFormDesignFun() {
    	formDesignDataGrid.datagrid('load', $.serializeObject($('#searchFormDesignForm')));
    }
    function cleanFormDesignFun() {
        $('#searchFormDesignForm input').val('');
       formDesignDataGrid.datagrid('load', {});
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
                            <div data-options="region:'north',border:false" style=" overflow: hidden;background-color: #fff">
        <form id="searchFormDesignForm">
            <table>
                <tr>
              <td>标题</td>
			  <td>
				<input name="title"   type="text" placeholder="请输入标题" class="easyui-text  span2" >
			 </td>
<td>
  <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchFormDesignFun();">查询</a>
<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanFormDesignFun();">清空</a>
</td></tr>

            </table>
        </form>
    </div>
    <div data-options="region:'center',border:true">
        <table id="formDesignDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="formDesignToolbar" style="display: none;">
    <a onclick="addFormDesignFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
</div>
